# Copyright (c) 2023 HiSilicon (Shanghai) Technologies CO., LIMITED.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# CROSS 为交叉编译工具链
CROSS = arm-himix100-linux-
CC	= @echo " GCC	$@"; $(CROSS)gcc
LD	= @echo " LD	$@"; $(CROSS)ld
AR	= @echo " AR	$@"; $(CROSS)ar
RM	= @echo " RM	$@"; rm -f
STRIP	= @echo "STRIP  $@"; $(CROSS)strip

# INCDIR_COMMON 和 INCDIR_BLE 为头文件路径
# INCDIR_SEC 为安全函数路径
TOPDIR = ./
INCDIR_TOP = $(TOPDIR)/inc/
INCDIR_COMMON = ../../../../../include/bsle/common/
INCDIR_BLE = ../../../../../include/bsle/sle/
INCDIR_SEC = ../../../../../driver/platform/libc_sec/include/
INCDIR_DRV = ../../../../../driver/platform/drv/include/
INCDIR_PLA = ../../../../../driver/platform/osal/include/
SRCDIR = $(TOPDIR)/src/
LIBDIR = $(TOPDIR)/lib/

CFLAGS	+=	-I$(INCDIR_TOP) -I$(INCDIR_COMMON) -I$(INCDIR_BLE) -I$(INCDIR_SEC) -I$(INCDIR_DRV) -I$(INCDIR_PLA)
CFLAGS	+= -Wall -Os #--std=c++11
LDFLAGS	+= -lm -lpthread -lrt -ldl -Wl,--gc-sections

SRCS := $(wildcard $(SRCDIR)/*.c)
SRCS += $(wildcard $(TOPDIR)/*.c)
OBJS := $(patsubst %.c,%.o,$(filter %.c,$(SRCS)))

TARGET	= $(TOPDIR)/sle_client_sample

all: $(TARGET)

$(TARGET): $(OBJS)
	echo -e "\e[36m<):$@; <):$^\e[0m"
	$(info $($(LIBDIR)/*.a))
	$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ -Xlinker "-(" $(LIBDIR)/*.a -Xlinker "-)"
	$(STRIP) --strip-unneeded -s $@
	
.c.o:
	$(CC) $(CFLAGS) -c -o $@ $<

clean:
	rm -f $(TARGET) $(OBJS) $(EXEC_OBJS);
	find ./ -type f \( -name '*.elf*' -o -name '*.gdb' \) | xargs rm -f

# $(RM) $@;
# $(STRIP) $@
